package com.example.demo.common;

public class JsonResult<T>{
    private Integer code;    //返回给前端的状态码，用于表示操作的成功或失败，以及可能的错误类型
    private String message; //返回给前端的提示信息，用于解释状态码或给出更详细的说明
    private T data;  //用于携带返回给前端的具体数据

    public static <T>JsonResult<T> ok(Integer code,String message,T data) {
        return new JsonResult<>(code,message,data);
    }
    public static <T>JsonResult<T> ok(String message,T data) {
        return new JsonResult<>(2000,message,data);
    }

    public static <T> JsonResult<T> ok(String message) {//给增删改用的

        return new JsonResult<>(2000,message,null);
    }
    public static <T> JsonResult<T> ok(T data) {//给增删改用的

        return new JsonResult<>(2000,"success",data);
    }
    public static <T> JsonResult<T> ok()
    {//给增删改用的
        return new JsonResult<>(2000,"success",null);
    }
    public static <T> JsonResult<T> fail(Integer code, String message) {

        return new JsonResult<>(code,message,null);
    }
    public static <T> JsonResult<T> fail() {

        return new JsonResult<>(5000,"服务异常",null);
    }

    public JsonResult(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}